﻿//生成[BlogComment]Service代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FineAdmin.IService;
using FineAdmin.Model;
using FineAdmin.IRepository;
using FineAdmin.Common;

namespace FineAdmin.Service
{
    public class BlogCommentService : BaseService<BlogCommentModel>, IBlogCommentService
    {
        public IBlogCommentRepository BlogCommentRepository { get; set; }
        public IEnumerable<BlogCommentModel> GetBlogCommentList()
        {
            return BlogCommentRepository.GetBlogCommentList();
        }

        public IEnumerable<BlogCommentModel> GetList(BlogCommentModel filter, PageInfo pageInfo, out int total)
        {
            string where = "Where 1=1";
            string _orderBy = string.Empty;
            if (filter.Type == 1) {
                where += "and PostsId="+filter.PostsId;
            }
            if (filter.State.HasValue)
            {
                where += "and State=" + filter.State;
            }
            if (!string.IsNullOrEmpty(pageInfo.field))
            {
                _orderBy = string.Format(" ORDER BY {0} {1}", pageInfo.field, pageInfo.order);
            }
            else
            {
                _orderBy = " ORDER BY CreateTime desc";
            }

            var list = BaseRepository.GetByPage(new SearchFilter { pageIndex = pageInfo.page, pageSize = pageInfo.limit, returnFields = pageInfo.returnFields, param = filter, where = where, orderBy = _orderBy }, out total);
            return list;
        }

        public dynamic GetListByFilter(BlogCommentModel filter, PageInfo pageInfo)
        {
            string _where = " where 1=1";
            if (filter.Type.HasValue)
            {
                _where += string.Format(" and Type = {0}", filter.Type.Value);
            }
            return GetListByFilter(filter, pageInfo, _where);
        }

        public IEnumerable<BlogCommentModel> GetListByFilter(BlogCommentModel filter, PageInfo pageInfo, out int total, string where = null)
        {
            string _where = " where 1=1";
            if (filter.Type.HasValue)
            {

                _where += string.Format(" and Type = {0}", filter.Type.Value);
            }
            return GetPageUnite(filter, pageInfo, out total, _where);
        }
    }

}